package com.kuaikan.cnbeta.activity;

import java.util.List;

import net.tsz.afinal.annotation.view.ViewInject;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.bsi.app.BaseActivity;
import com.bsi.app.OnBackPressedExitActivity;
import com.kuaikan.cnbeta.R;
import com.kuaikan.cnbeta.adapter.NewsTitleAdapter;
import com.kuaikan.cnbeta.pojo.News;
import com.kuaikan.cnbeta.srvc.NewsSrvc;
import com.kuaikan.cnbeta.util.Const;

public class HomeActivity extends OnBackPressedExitActivity {
	
	NewsTitleAdapter newsTitleAdapter;
	List<News> allList;
//	private static final String url="www.cnbeta.com";

	@ViewInject(id=R.id.lvNewsTitle) ListView lvNewsTitle;
	@ViewInject(id=R.id.btnRefresh,click="btnRefresh") Button btnRefresh;
	NewsSrvc newsSrvc=srvcFactory.getNewsSrvc();
	@Override
	public void setCurrentContentView() {
		setContentView(R.layout.act_home);
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		allList=(List<News>) getIntent().getSerializableExtra(LoadingActivity.NEWS_TITLE_LIST);
		initLv();
	}

	
	
	@Override
	protected void onResume() {
		super.onResume();
		
	}
	
	void initLv(){
	
		newsTitleAdapter=new NewsTitleAdapter(allList, this);
		lvNewsTitle.setAdapter(newsTitleAdapter);
		new Thread(){
			public void run() {
				srvcFactory.getNewsSrvc().saveNewsList(allList);
			};
		}.start();
	}
	
	public void btnRefresh(View v){
		new Thread(){
			public void run() {
				try {
					allList=newsSrvc.getNewsTitles(Const.CN_BETA_URL);
				} catch (Exception e) {
					e.printStackTrace();
				}
			};
		}.start();
	}
	
}
